Make sure that accesses to the machine_to_phys table all go through
authorsos22@douglas.cl.cam.ac.uk <sos22@douglas.cl.cam.ac.uk>
Wed, 23 Nov 2005 12:34:25 +0000 (13:34 +0100)
committersos22@douglas.cl.cam.ac.uk <sos22@douglas.cl.cam.ac.uk>
Wed, 23 Nov 2005 12:34:25 +0000 (13:34 +0100)
suitable macros.

Signed-off-by: Steven Smith, sos22@cam.ac.uk
tools/libxc/xc_linux_save.c
xen/arch/x86/x86_32/mm.c
xen/arch/x86/x86_32/traps.c

index ade255f9136c33b8b3daee1a8cc602cf575f5313..0cced84152630af6888ca5bf558408c1b3af9fdd 100644 (file)
@@ -44,6 +44,9 @@ static unsigned long *live_p2m = NULL;
 /* Live mapping of system MFN to PFN table. */
 static unsigned long *live_m2p = NULL;
 
+/* grep fodder: machine_to_phys */
+
+#define mfn_to_pfn(_mfn) live_m2p[(_mfn)]
 
 /*
  * Returns TRUE if the given machine frame number has a unique mapping
@@ -51,8 +54,8 @@ static unsigned long *live_m2p = NULL;
  */
 #define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn)          \
 (((_mfn) < (max_mfn)) &&                        \
- ((live_m2p[_mfn] < (max_pfn)) &&               \
-  (live_p2m[live_m2p[_mfn]] == (_mfn))))
+ ((mfn_to_pfn(_mfn) < (max_pfn)) &&               \
+  (live_p2m[mfn_to_pfn(_mfn)] == (_mfn))))
     
  
 /* Returns TRUE if MFN is successfully converted to a PFN. */
@@ -63,7 +66,7 @@ static unsigned long *live_m2p = NULL;
     if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) )                       \
         _res = 0;                                               \
     else                                                        \
-        *(_pmfn) = live_m2p[mfn];                               \
+        *(_pmfn) = mfn_to_pfn(mfn);                             \
     _res;                                                       \
 })
 
@@ -477,9 +480,7 @@ void canonicalize_pagetable(unsigned long type, unsigned long pfn,
                         type, i, (unsigned long long)pte, mfn); 
                 pfn = 0; /* zap it - we'll retransmit this page later */
             } else 
-                pfn = live_m2p[mfn];
-            
-
+                pfn = mfn_to_pfn(mfn);
             
             pte &= 0xffffff0000000fffULL;
             pte |= (uint64_t)pfn << PAGE_SHIFT;
@@ -815,9 +816,9 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
         for (i = 0; i < max_pfn; i++) {
 
             mfn = live_p2m[i];
-            if((mfn != 0xffffffffUL) && (live_m2p[mfn] != i)) { 
+            if((mfn != 0xffffffffUL) && (mfn_to_pfn(mfn) != i)) { 
                 DPRINTF("i=0x%x mfn=%lx live_m2p=%lx\n", i, 
-                        mfn, live_m2p[mfn]);
+                        mfn, mfn_to_pfn(mfn));
                 err++;
             }
         }
@@ -882,7 +883,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
                     DPRINTF("%d pfn= %08lx mfn= %08lx %d  [mfn]= %08lx\n",
                             iter, (unsigned long)n, live_p2m[n],
                             test_bit(n, to_send), 
-                            live_m2p[live_p2m[n]&0xFFFFF]);
+                            mfn_to_pfn(live_p2m[n]&0xFFFFF));
                 }
                 
                 if (!last_iter && test_bit(n, to_send)&& test_bit(n, to_skip)) 
@@ -954,7 +955,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
                             iter, 
                             (pfn_type[j] & LTAB_MASK) | pfn_batch[j],
                             pfn_type[j],
-                            live_m2p[pfn_type[j]&(~LTAB_MASK)],
+                            mfn_to_pfn(pfn_type[j]&(~LTAB_MASK)),
                             csum_page(region_base + (PAGE_SIZE*j)));
                 
                 /* canonicalise mfn->pfn */
@@ -1141,7 +1142,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
         ERR("PT base is not in range of pseudophys map");
         goto out;
     }
-    ctxt.ctrlreg[3] = live_m2p[ctxt.ctrlreg[3] >> PAGE_SHIFT] <<
+    ctxt.ctrlreg[3] = mfn_to_pfn(ctxt.ctrlreg[3] >> PAGE_SHIFT) <<
         PAGE_SHIFT;
 
     if (!write_exact(io_fd, &ctxt, sizeof(ctxt)) ||
index 64491f02d977d57c5dbc2e665e59576496565325..c89ee44967ba68787e5c6949b0e36d50c4a721b8 100644 (file)
@@ -106,7 +106,9 @@ void __init paging_init(void)
         idle_pg_table_l2[l2_linear_offset(RO_MPT_VIRT_START) + i] =
             l2e_from_page(pg, (__PAGE_HYPERVISOR | _PAGE_PSE) & ~_PAGE_RW);
     }
-    memset((void *)RDWR_MPT_VIRT_START, 0x55, mpt_size);
+
+    for ( i = 0; i < max_page; i++)
+        set_pfn_from_mfn(i, 0x55555555);
 
     /* Create page tables for ioremap(). */
     for ( i = 0; i < (IOREMAP_MBYTES >> (L2_PAGETABLE_SHIFT - 20)); i++ )
index 9dbe94178e2b23fc951262393146d1711e174aa3..543b10c04bcd60ab4c98db33026609e2c0f585a8 100644 (file)
@@ -103,7 +103,7 @@ void show_page_walk(unsigned long addr)
 
     ptab = map_domain_page(mfn);
     ent  = ptab[l2_table_offset(addr)];
-    pfn  = machine_to_phys_mapping[(u32)(ent >> PAGE_SHIFT)]; 
+    pfn  = get_pfn_from_mfn(ent >> PAGE_SHIFT);
     printk("  L2 = %"PRIpte" %08lx %s\n", ent, pfn, 
            (ent & _PAGE_PSE) ? "(PSE)" : "");
     unmap_domain_page(ptab);
@@ -113,7 +113,7 @@ void show_page_walk(unsigned long addr)
 
     ptab = map_domain_page(ent >> PAGE_SHIFT);
     ent  = ptab[l1_table_offset(addr)];
-    pfn  = machine_to_phys_mapping[(u32)(ent >> PAGE_SHIFT)]; 
+    pfn  = get_pfn_from_mfn(ent >> PAGE_SHIFT);
     printk("   L1 = %"PRIpte" %08lx\n", ent, pfn);
     unmap_domain_page(ptab);
 }